/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using DOAN.DO;
/// <summary>
/// Summary description for DethiDAL
/// </summary>
namespace DOAN.DAL
{

    public class DethiDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public DethiDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(DethiDO objDethiDO)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spDethi_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Mamonhoc", SqlDbType.VarChar);
            Sqlparam.Value = objDethiDO.Mamonhoc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Tieude", SqlDbType.NVarChar);
            Sqlparam.Value = objDethiDO.Tieude;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Macauhoi", SqlDbType.NVarChar);
            Sqlparam.Value = objDethiDO.Macauhoi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Socau", SqlDbType.Int);
            Sqlparam.Value = objDethiDO.Socau;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Sodiem", SqlDbType.Float);
            Sqlparam.Value = objDethiDO.Sodiem;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Thoigian", SqlDbType.Int);
            Sqlparam.Value = objDethiDO.Thoigian;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Ngaytao", SqlDbType.VarChar);
            Sqlparam.Value = objDethiDO.Ngaytao;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Tentaikhoan", SqlDbType.VarChar);
            Sqlparam.Value = objDethiDO.Tentaikhoan;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(DethiDO objDethiDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spDethi_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Madethi", SqlDbType.VarChar);
            Sqlparam.Value = objDethiDO.Madethi;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Mamonhoc", SqlDbType.VarChar);
            Sqlparam.Value = objDethiDO.Mamonhoc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Tieude", SqlDbType.NVarChar);
            Sqlparam.Value = objDethiDO.Tieude;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Socau", SqlDbType.Int);
            Sqlparam.Value = objDethiDO.Socau;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Sodiem", SqlDbType.Float);
            Sqlparam.Value = objDethiDO.Sodiem;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Thoigian", SqlDbType.Int);
            Sqlparam.Value = objDethiDO.Thoigian;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Ngaytao", SqlDbType.VarChar);
            Sqlparam.Value = objDethiDO.Ngaytao;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Tentaikhoan", SqlDbType.VarChar);
            Sqlparam.Value = objDethiDO.Tentaikhoan;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(DethiDO objDethiDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spDethi_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Madethi", SqlDbType.VarChar);
            Sqlparam.Value = objDethiDO.Madethi;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spDethi_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }


        public DataTable GetByMonAndUser(string suser, string mamon)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spDethi_GetByUserMon";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@mon", SqlDbType.VarChar);
            Sqlparam.Value = mamon;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@user", SqlDbType.VarChar);
            Sqlparam.Value = suser;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable GetByMon(string mamon)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spDethi_GetByMon";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@mon", SqlDbType.VarChar);
            Sqlparam.Value = mamon;
            Sqlcomm.Parameters.Add(Sqlparam);


            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DethiDO Select(DethiDO objDethiDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spDethi_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Madethi", SqlDbType.VarChar);
            Sqlparam.Value = objDethiDO.Madethi;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["Madethi"]))
                    objDethiDO.Madethi = Convert.ToInt32(dr["Madethi"]);
                if (!Convert.IsDBNull(dr["Mamonhoc"]))
                    objDethiDO.Mamonhoc = Convert.ToString(dr["Mamonhoc"]);
                if (!Convert.IsDBNull(dr["Macauhoi"]))
                    objDethiDO.Macauhoi = Convert.ToString(dr["Macauhoi"]);
                if (!Convert.IsDBNull(dr["Tieude"]))
                    objDethiDO.Tieude = Convert.ToString(dr["Tieude"]);
                if (!Convert.IsDBNull(dr["Socau"]))
                    objDethiDO.Socau = Convert.ToInt32(dr["Socau"]);
                if (!Convert.IsDBNull(dr["Sodiem"]))
                    objDethiDO.Sodiem = Convert.ToDouble(dr["Sodiem"]);
                if (!Convert.IsDBNull(dr["Thoigian"]))
                    objDethiDO.Thoigian = Convert.ToInt32(dr["Thoigian"]);
                if (!Convert.IsDBNull(dr["Ngaytao"]))
                    objDethiDO.Ngaytao = Convert.ToString(dr["Ngaytao"]);
                if (!Convert.IsDBNull(dr["Tentaikhoan"]))
                    objDethiDO.Tentaikhoan = Convert.ToString(dr["Tentaikhoan"]);

            }
            return objDethiDO;
        }

        public DethiDO SelectDeThi(DethiDO objDethiDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spDethi_ThiGetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Madethi", SqlDbType.VarChar);
            Sqlparam.Value = objDethiDO.Madethi;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["Madethi"]))
                    objDethiDO.Madethi = Convert.ToInt32(dr["Madethi"]);
                if (!Convert.IsDBNull(dr["Mamonhoc"]))
                    objDethiDO.Mamonhoc = Convert.ToString(dr["Mamonhoc"]);
                if (!Convert.IsDBNull(dr["Macauhoi"]))
                    objDethiDO.Macauhoi = Convert.ToString(dr["Macauhoi"]);
                if (!Convert.IsDBNull(dr["Tieude"]))
                    objDethiDO.Tieude = Convert.ToString(dr["Tieude"]);
                if (!Convert.IsDBNull(dr["Socau"]))
                    objDethiDO.Socau = Convert.ToInt32(dr["Socau"]);
                if (!Convert.IsDBNull(dr["Sodiem"]))
                    objDethiDO.Sodiem = Convert.ToDouble(dr["Sodiem"]);
                if (!Convert.IsDBNull(dr["Thoigian"]))
                    objDethiDO.Thoigian = Convert.ToInt32(dr["Thoigian"]);
                if (!Convert.IsDBNull(dr["Ngaytao"]))
                    objDethiDO.Ngaytao = Convert.ToString(dr["Ngaytao"]);
                if (!Convert.IsDBNull(dr["Tentaikhoan"]))
                    objDethiDO.Tentaikhoan = Convert.ToString(dr["Tentaikhoan"]);

            }
            return objDethiDO;
        }
        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spDethi_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrDethiDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    DethiDO objDethiDO = new DethiDO();
                    if (!Convert.IsDBNull(dr["Madethi"]))
                        objDethiDO.Madethi = Convert.ToInt32(dr["Madethi"]);
                    if (!Convert.IsDBNull(dr["Mamonhoc"]))
                        objDethiDO.Mamonhoc = Convert.ToString(dr["Mamonhoc"]);
                    if (!Convert.IsDBNull(dr["Tieude"]))
                        objDethiDO.Tieude = Convert.ToString(dr["Tieude"]);
                    if (!Convert.IsDBNull(dr["Socau"]))
                        objDethiDO.Socau = Convert.ToInt32(dr["Socau"]);
                    if (!Convert.IsDBNull(dr["Sodiem"]))
                        objDethiDO.Sodiem = Convert.ToDouble(dr["Sodiem"]);
                    if (!Convert.IsDBNull(dr["Thoigian"]))
                        objDethiDO.Thoigian = Convert.ToInt32(dr["Thoigian"]);
                    if (!Convert.IsDBNull(dr["Ngaytao"]))
                        objDethiDO.Ngaytao = Convert.ToString(dr["Ngaytao"]);
                    if (!Convert.IsDBNull(dr["Tentaikhoan"]))
                        objDethiDO.Tentaikhoan = Convert.ToString(dr["Tentaikhoan"]);
                    arrDethiDO.Add(objDethiDO);
                }
            }
            return arrDethiDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spDethi_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
